<template>
  <div class="mod-config">
    <basic-container>
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-button
            v-if="permissions.bulletin_srsbbulletinpartymember_add"
            icon="el-icon-plus"
            type="primary"
            @click="addOrUpdateHandle()"
            >新增</el-button
          >
          <el-button
            class="filter-item"
            v-if="permissions.bulletin_srsbbulletinpartymember_import"
            plain
            type="primary"
            size="small"
            icon="el-icon-upload"
            @click="$refs.excelUpload.show()"
            >导入
          </el-button>
          <el-button
            class="filter-item"
            v-if="permissions.bulletin_srsbbulletinpartymember_export"
            plain
            type="primary"
            size="small"
            icon="el-icon-download"
            @click="exportExcel()"
            >导出
          </el-button>
        </el-form-item>
      </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column
            prop="id"
            header-align="center"
            align="center"
            label="主键id"
          >
          </el-table-column>
          <el-table-column
            prop="partyOrganization"
            header-align="center"
            align="center"
            label="所属党组织"
          >
          </el-table-column>
          <el-table-column
            prop="code"
            header-align="center"
            align="center"
            label="党组织code"
          >
          </el-table-column>
          <el-table-column
            prop="fullName"
            header-align="center"
            align="center"
            label="姓名"
          >
          </el-table-column>
          <el-table-column
            prop="cardNo"
            header-align="center"
            align="center"
            label="身份证号码"
          >
          </el-table-column>
          <el-table-column
            prop="phoneNo"
            header-align="center"
            align="center"
            label="手机号码"
          >
          </el-table-column>
          <el-table-column
            prop="payPartyDues"
            header-align="center"
            align="center"
            label="交纳党费"
          >
          </el-table-column>
          <el-table-column
            prop="gender"
            header-align="center"
            align="center"
            label="性别 0-男 1-女"
          >
          </el-table-column>
          <el-table-column
            prop="age"
            header-align="center"
            align="center"
            label="年龄"
          >
          </el-table-column>
          <el-table-column
            prop="partyAge"
            header-align="center"
            align="center"
            label="党龄"
          >
          </el-table-column>
          <el-table-column
            prop="education"
            header-align="center"
            align="center"
            label="学历"
          >
          </el-table-column>
          <el-table-column
            prop="workingTime"
            header-align="center"
            align="center"
            label="参加工作时间"
          >
          </el-table-column>
          <el-table-column
            prop="nation"
            header-align="center"
            align="center"
            label="名族"
          >
          </el-table-column>
          <el-table-column
            prop="birthday"
            header-align="center"
            align="center"
            label="出生年月"
          >
          </el-table-column>
          <el-table-column
            prop="joinDate"
            header-align="center"
            align="center"
            label="入党年月"
          >
          </el-table-column>
          <el-table-column
            prop="major"
            header-align="center"
            align="center"
            label="专业"
          >
          </el-table-column>
          <el-table-column
            prop="employer"
            header-align="center"
            align="center"
            label="任职单位"
          >
          </el-table-column>
          <el-table-column
            prop="lastPaymentDate"
            header-align="center"
            align="center"
            label="最后交费时间"
          >
          </el-table-column>
          <el-table-column
            prop="createTime"
            header-align="center"
            align="center"
            label="创建时间"
          >
          </el-table-column>
          <el-table-column
            prop="createBy"
            header-align="center"
            align="center"
            label="创建人"
          >
          </el-table-column>
          <el-table-column
            prop="updateTime"
            header-align="center"
            align="center"
            label="创建时间"
          >
          </el-table-column>
          <el-table-column
            prop="updateBy"
            header-align="center"
            align="center"
            label="更新人"
          >
          </el-table-column>
          <el-table-column header-align="center" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                v-if="permissions.bulletin_srsbbulletinpartymember_edit"
                type="text"
                size="small"
                icon="el-icon-edit"
                @click="addOrUpdateHandle(scope.row.id)"
                >修改</el-button
              >
              <el-button
                v-if="permissions.bulletin_srsbbulletinpartymember_del"
                type="text"
                size="small"
                icon="el-icon-delete"
                @click="deleteHandle(scope.row.id)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next, jumper"
        >
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></table-form>
    </basic-container>
    <!--excel 模板导入 -->
    <excel-upload
      ref="excelUpload"
      title="用户信息导入"
      url="/bulletin/srsbbulletinpartymember/import"
      temp-name="党员花名册模板.xls"
      temp-url="https://h2-shanghai-blog.oss-cn-shanghai.aliyuncs.com/srsb/4eb4d00a320d4c92937266e7a5abeda1.xls"
      downType="1"
      @refreshDataList="handleRefreshChange"
    ></excel-upload>
  </div>
</template>

<script>
import { fetchList, delObj } from "@/api/srsbbulletinpartymember";
import TableForm from "./srsbbulletinpartymember-form";
import { mapGetters } from "vuex";
import ExcelUpload from "@/components/upload/excel";
export default {
  data() {
    return {
      dataForm: {
        key: "",
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
    };
  },
  components: {
    TableForm,
    ExcelUpload,
  },
  created() {
    this.getDataList();
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    handleRefreshChange() {
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      fetchList(
        Object.assign({
          current: this.pageIndex,
          size: this.pageSize,
        })
      ).then((response) => {
        this.dataList = response.data.data.records;
        this.totalPage = response.data.data.total;
      });
      this.dataListLoading = false;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    exportExcel() {
      this.downBlobFile(
        "/bulletin/srsbbulletinpartymember/export",
        {},
        "党员信息.xlsx"
      );
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      this.$confirm("是否确认删除ID为" + id, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(id);
        })
        .then((data) => {
          this.$message.success("删除成功");
          this.getDataList();
        })
        .catch(() => {});
    },
  },
};
</script>
